import jfRequest from "../../index";
import JFRequest from "@/service/request";
import { ILoginReq, ILoginResult } from "./types";
import { IResultType } from "types/request";
import { APP_ID, APP_KEY, GET_ORGCODE_URL } from "@/service/request/config";
export function accountLoginRequest(data: ILoginReq) {
  return jfRequest.post<IResultType<ILoginResult>>({
    url: "/api/v1/login",
    data,
  });
}
export function requestSysInfo(data: any) {
  return jfRequest.get<IResultType>({
    url: "/api/v1/getInfo",
    data,
    showLoading: false,
  });
}

export function requestUserMenusByRoleId(id: number) {
  return jfRequest.get<IResultType>({
    url: "/public/getMenuList",
    showLoading: false,
  });
}

// 获取token和orgCode
export async function getTokenAddOrgCode(
  appToken: String,
  timeStamp: number,
  accessToken: string
) {
  const appId = "JF-ISWCC-WEB";
  const jfRequest = new JFRequest({
    baseURL: GET_ORGCODE_URL,
    timeout: 30000,
    interceptors: {
      requestIntercepter: (config) => {
        config.headers.timeStamp = timeStamp;
        config.headers.appId = appId;
        config.headers.appToken = appToken;
        return config;
      },
      requestInterceptorCatch: (err) => {
        return err;
      },
      responseIntercepter: (config) => {
        return config;
      },
      responseInterceptorCatch: (err) => {
        return err;
      },
    },
  });
  const data = {
    appId: APP_ID,
    appKey: APP_KEY,
    accessToken,
  };
  return jfRequest.post<IResultType<any>>({
    url: "/service/isptl/open/public/loginByAccessToken",
    showLoading: true,
    data: {
      data,
    },
  });
}
